package demo1;

import java.util.Scanner;

public class CustomExceptionTest {
    public static void main(String[] args) {
        Scanner scanner = null;
        int count = 3;
        scanner = new Scanner(System.in);
        do {
            LogIn logIn = new LogIn();
            System.out.println("请输入用户名：");
            logIn.setUsername(scanner.nextLine());
            System.out.println("请输入密码：");
            logIn.setPassword(scanner.nextLine());
            try {
                logIn.login();
            } catch (UsernameException e) {
                e.printStackTrace();
            } catch (PasswordException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if(scanner != null && count == 0) {
                    scanner.close();
                }
                count--;
                if(count != 0) {
                    System.out.println("你还有" + count + "次机会！");
                }else if(count == 0) {
                    System.out.println("请1分钟后在试");
                }
            }
        } while (count != 0);
    }
}
